1 from tkinter import *
2
3 #Import Tk themed widgets

4 from
tkinter import ttk
5
6 class
Loan_Calculator():
7
8     def __init__(self):
9          
10         #creating the root window here
11         root = Tk()
12
13         #
set the title
14         root.title(
'Loan Calculator')
15
16         #
set the geometry
17         #root.geometry(
'250x300')
18
19         #
set the background color
20         root.config(background=
'beige')
21
22         #creating the labels
23         Label(root,text=
'Annual Interest Rate',bg='Beige' , borderwidth = 4).grid(row=1,column = 1,sticky = W)
24
25         Label(root,text=
'Numbers of Years',bg='Beige' , borderwidth = 4).grid(row=2,column = 1,sticky = W)
26
27         Label(root,text=
'Loan Ammount',bg='Beige' , borderwidth = 4).grid(row=3,column = 1,sticky = W)
28
29         Label(root,text=
'Monthly Payment',bg='Beige' , borderwidth = 4).grid(row=4 ,column = 1,sticky = W)
30
31         Label(root,text=
'Total Payment',bg='Beige' , borderwidth = 4).grid(row=5,column = 1,sticky = W)
32
33         #Create the Entry Widgets
34         self.AnnualInterest = StringVar()
35         Entry(root, textvariable = self.AnnualInterest,justify = RIGHT).grid(row =
1,column = 2,sticky = E)
36
37         self.years = StringVar()
38         Entry(root, textvariable = self.years,justify = RIGHT).grid(row =
2,column = 2,sticky = E)
39
40         self.amount = StringVar()
41         Entry(root, textvariable = self.amount,justify = RIGHT).grid(row =
3,column = 2,sticky = E)
42
43         self.monthlyPayment = StringVar()
44         Label(root, textvariable = self.monthlyPayment).grid(row =
4,column = 2,sticky = E)
45
46         self.TotalPayment = StringVar()
47         Label(root, textvariable = self.TotalPayment).grid(row =
5,column = 2,sticky = E)
48
49         #CREATING BUTTONS
50         compute = Button(root, text =
'Compute Loan',command = self.ComputePayment).grid(row = 6, column = 2,sticky = E)
51
52         root.mainloop()
53
54     # compute the total payment.
55     def ComputePayment(self):
56                   
57         month = self.getMonthlyPayment(
58         
float(self.amount.get()),
59         
float(self.AnnualInterest.get()) / 1200,
60         
int(self.years.get()))
61   
62         self.monthlyPayment.
set(format(month, '10.2f'))
63
64         total =
float(self.monthlyPayment.get()) * 12 * int(self.years.get())
65   
66         self.TotalPayment.
set(format(total, '10.2f'))
67   
68     def getMonthlyPayment(self, loanAmount, monthlyInterestRate, numberOfYears):
69         # compute the monthly payment.
70         month = loanAmount * monthlyInterestRate / (
1
71         -
1 / (1 + monthlyInterestRate) ** (numberOfYears * 12))
72         
return month;
73
74 Loan_Calculator()


Gõ tìm kiếm nhanh...